'''
Base class for Jobs. A thread with extras:
* field to indicate if the job was successful
* field for the last error encountered
* jobs can be stopped

Licensed under the GPL.

@author: screwdriver
'''

'''
Version history:
----------------
2009-03-27 screwdirver Created.
'''

from debug import debug;

from threading import Thread;
from string import Template;

MAJOR_VERSION = 1;
MINOR_VERSION = 0;
MAINTENANCE = 0;

VERSION = [MAJOR_VERSION,".", MINOR_VERSION,".", MAINTENANCE];


class Job(Thread):
	
	
	def successful(): #@NoSelf
		doc = """Indicates, if the instance was sucessful.""" #@UnusedVariable
		
		def fget(self):
			return self._successful
			
		def fset(self, value):
			self._successful = value
			
		def fdel(self):
			del self._successful
			
		return locals()
		
	successful = property(**successful())
	
	def lasterror(): #@NoSelf
		doc = """Human readable reason for the failure.""" #@UnusedVariable
		
		def fget(self):
			return self._lasterror
			
		def fset(self, value):
			self._lasterror = value
			
		def fdel(self):
			del self._lasterror
			
		return locals()
		
	lasterror = property(**lasterror())
	
	def stopped(): #@NoSelf
		doc = """Stop the download and indicate if the download has been stopped.""" #@UnusedVariable
		
		def fget(self):
			return self._stopped
			
		def fset(self, value):
			self._stopped = value
			
		def fdel(self):
			del self._stopped
			
		return locals()
		
	stopped = property(**stopped())
	
	def __init__(self):
		Thread.__init__(self);
		self.stopped = False;
		self.successful = False;
		self.lasterror = None;
	
	def run(self):
		pass;
	
	def stop(self):
		self.stopped = True;
